/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dp1.titandevelop.titano.view.almac;

//import java.awt.Dimension;
import dp1.titandevelop.titano.service.AlmacenService;
import dp1.titandevelop.titano.view.CambiarPassword;
import dp1.titandevelop.titano.view.LoginT;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;

/**
 *
 * @author christianjuarez
 */
public class ModulosT_ALM extends javax.swing.JFrame {

    //Atributos de las ventanas a observar
    public static ModulosT_ALM_AdmAlm menuAdmAlm = null;
    public static ModulosT_ALM_AlmNuevo ventanaNuevo = null;
    public static ModulosT_ALM_AlmEdita ventanaEdita = null;
    public static ModulosT_ALM_AdmMovMat menuAdmMov = null;
    public static ModulosT_ALM_MovMatNuevo ventana2Nuevo = null;
    public ModulosT_ALM_ReporteMovimientos ventanaReporte = null;
    
    public static ModulosT_ALM_AdmTMov menuAdmTMov = null;
    public static ModulosT_ALM_Zona menuZona = null;

    
    private BufferedImage imgFondo;
    public class HiloAlmacen extends Thread{
    
        private AlmacenService servA = new AlmacenService();
        private Component pantalla;
        
        private HiloAlmacen (Component root){
            pantalla = root;
        }
        
        @Override
        public void run(){
                
                while(true){
                    try {                                               
                        String mensaje = servA.verificaStockProductos();
                        if(mensaje!=null){
                            JOptionPane.showConfirmDialog(pantalla,mensaje,"Aviso!",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE);
                        }
                        sleep(10000);
                        stop();
                    } catch (InterruptedException ex) {
                        Logger.getLogger(ModulosT_ALM.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
        }
    
    }
    
    
    public ModulosT_ALM() {
        initComponents();
        this.setLocationRelativeTo(null);
        this.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
        HiloAlmacen hilo = new HiloAlmacen(this.getRootPane());
        hilo.start();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        try {
            //this.getClass().getResource("/img/fondo.png").toURI();
            this.imgFondo = ImageIO.read(getClass().getResourceAsStream("/img/fondoTitanBright.png"));
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        escritorioAlmacen = new javax.swing.JDesktopPane(){
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(imgFondo, 0, 0, this);
            }

            @Override
            public Dimension getPreferredSize() {
                return new Dimension(imgFondo.getWidth(), imgFondo.getHeight());
            }

        };
        jPanel3 = new javax.swing.JPanel();
        lblUsuario1 = new javax.swing.JLabel();
        lblUsuarioLogeado1 = new javax.swing.JLabel();
        lblCorreo1 = new javax.swing.JLabel();
        lblCorreoLogeado1 = new javax.swing.JLabel();
        btnCambiarPW1 = new javax.swing.JButton();
        lblPerfil1 = new javax.swing.JLabel();
        lblPerfilLogeado1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        menuItemZona = new javax.swing.JMenuItem();
        menuAlmacen = new javax.swing.JMenuItem();
        menuMovimientosMaterial = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem4 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Módulo de Almacén");

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        lblUsuario1.setText("Usuario:");

        lblUsuarioLogeado1.setText(LoginT.empleadoLogin.getNombres()+" "+LoginT.empleadoLogin.getApellidop()+" "+LoginT.empleadoLogin.getApellidom()+" "+"("+LoginT.userLogin.getUsuario()+")");

        lblCorreo1.setText("Correo:");

        lblCorreoLogeado1.setText(LoginT.empleadoLogin.getEmail());

        btnCambiarPW1.setText("Cambiar Password");
        btnCambiarPW1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        btnCambiarPW1.setPreferredSize(new java.awt.Dimension(121, 20));
        btnCambiarPW1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCambiarPW1ActionPerformed(evt);
            }
        });

        lblPerfil1.setText("Perfil:");

        lblPerfilLogeado1.setText(LoginT.perfilLogin.getDescripcion());

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/usuario.png"))); // NOI18N

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/perfilesactivos.png"))); // NOI18N

        jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/correo.png"))); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblUsuario1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblUsuarioLogeado1)
                .addGap(27, 27, 27)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblCorreo1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblCorreoLogeado1)
                .addGap(32, 32, 32)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblPerfil1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblPerfilLogeado1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnCambiarPW1, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblUsuario1)
                    .addComponent(lblUsuarioLogeado1)
                    .addComponent(lblCorreo1)
                    .addComponent(lblCorreoLogeado1)
                    .addComponent(btnCambiarPW1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblPerfil1)
                    .addComponent(lblPerfilLogeado1)
                    .addComponent(jLabel3)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)))
        );

        jMenu1.setText("Administrar");

        menuItemZona.setText("Zona");
        menuItemZona.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemZonaActionPerformed(evt);
            }
        });
        jMenu1.add(menuItemZona);

        menuAlmacen.setText("Almacen");
        menuAlmacen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuAlmacenActionPerformed(evt);
            }
        });
        jMenu1.add(menuAlmacen);

        menuMovimientosMaterial.setText("Movimientos Material");
        menuMovimientosMaterial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuMovimientosMaterialActionPerformed(evt);
            }
        });
        jMenu1.add(menuMovimientosMaterial);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Reportes");

        jMenuItem4.setText("Kardex");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem4);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addComponent(escritorioAlmacen)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(escritorioAlmacen, javax.swing.GroupLayout.DEFAULT_SIZE, 339, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void menuAlmacenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuAlmacenActionPerformed
        // Almacen  ID 14

        Integer i = 0;
        for (; i < LoginT.permisosxperfil.size(); i++) {
            if (14 == (Integer) LoginT.idspermisosxperfil.get(i)) {
                menuAdmAlm = new ModulosT_ALM_AdmAlm();
                this.escritorioAlmacen.add(menuAdmAlm);
                Dimension desktopSize = this.escritorioAlmacen.getSize();
                Dimension jInternalFrameSize = menuAdmAlm.getSize();
                menuAdmAlm.setLocation((desktopSize.width - jInternalFrameSize.width) / 2,
                        (desktopSize.height - jInternalFrameSize.height) / 4);
                menuAdmAlm.show();
                break;
            }
        }
        if (i >= LoginT.permisosxperfil.size()) {
            JOptionPane.showMessageDialog(this.escritorioAlmacen, "No puedes proceder, al parecer careces de permisos.",
                    "No posee permisos",
                    JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_menuAlmacenActionPerformed

    private void menuMovimientosMaterialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuMovimientosMaterialActionPerformed
        // Movimiento Material ID 15

        Integer i = 0;
        for (; i < LoginT.permisosxperfil.size(); i++) {
            if (15 == (Integer) LoginT.idspermisosxperfil.get(i)) {

                menuAdmMov = new ModulosT_ALM_AdmMovMat();
                this.escritorioAlmacen.add(menuAdmMov);
                Dimension desktopSize = this.getSize();
                Dimension jInternalFrameSize = menuAdmMov.getSize();
                menuAdmMov.setLocation((desktopSize.width - jInternalFrameSize.width) / 2,
                        (desktopSize.height - jInternalFrameSize.height) / 4);
                menuAdmMov.show();
                break;
    }//GEN-LAST:event_menuMovimientosMaterialActionPerformed
        }
        if (i >= LoginT.permisosxperfil.size()) {
            JOptionPane.showMessageDialog(this.escritorioAlmacen, "No puedes proceder, al parecer careces de permisos.",
                    "No posee permisos",
                    JOptionPane.WARNING_MESSAGE);
        }
    }
    private void menuItemZonaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemZonaActionPerformed
        //Administrar zona ID 16
        Integer i = 0;
        for (; i < LoginT.permisosxperfil.size(); i++) {
            if (16 == (Integer) LoginT.idspermisosxperfil.get(i)) {
                menuZona = new ModulosT_ALM_Zona();
                this.escritorioAlmacen.add(menuZona);
                Dimension desktopSize = this.getSize();
                Dimension jInternalFrameSize = menuZona.getSize();
                menuZona.setLocation((desktopSize.width - jInternalFrameSize.width) / 2,
                        (desktopSize.height - jInternalFrameSize.height) / 4);
                menuZona.show();
                break;
            }
        }
        if (i >= LoginT.permisosxperfil.size()) {
            JOptionPane.showMessageDialog(this.escritorioAlmacen, "No puedes proceder, al parecer careces de permisos.",
                    "No posee permisos",
                    JOptionPane.WARNING_MESSAGE);
        }

    }//GEN-LAST:event_menuItemZonaActionPerformed

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
            ventanaReporte= new ModulosT_ALM_ReporteMovimientos();
            this.escritorioAlmacen.add(ventanaReporte);
            Dimension desktopSize = this.getSize();
            Dimension jInternalFrameSize = ventanaReporte.getSize();
            ventanaReporte.setLocation((desktopSize.width - jInternalFrameSize.width) / 2,
                    (desktopSize.height - jInternalFrameSize.height) / 4);
            ventanaReporte.show();
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    private void btnCambiarPW1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCambiarPW1ActionPerformed

        CambiarPassword chngpw = new CambiarPassword(new javax.swing.JFrame(), true);
        chngpw.setLocationRelativeTo(null);
        chngpw.setVisible(true);
    }//GEN-LAST:event_btnCambiarPW1ActionPerformed
        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ModulosT_ALM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ModulosT_ALM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ModulosT_ALM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ModulosT_ALM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ModulosT_ALM().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCambiarPW1;
    private javax.swing.JDesktopPane escritorioAlmacen;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JLabel lblCorreo1;
    private javax.swing.JLabel lblCorreoLogeado1;
    private javax.swing.JLabel lblPerfil1;
    private javax.swing.JLabel lblPerfilLogeado1;
    private javax.swing.JLabel lblUsuario1;
    private javax.swing.JLabel lblUsuarioLogeado1;
    private javax.swing.JMenuItem menuAlmacen;
    private javax.swing.JMenuItem menuItemZona;
    private javax.swing.JMenuItem menuMovimientosMaterial;
    // End of variables declaration//GEN-END:variables
}
